package com.thinkfit.jy.utils;

import com.common.lib.utils.BaseUtils;

public class DateUtils {

    private static DateUtils dateUtils;

    public static DateUtils getInstance(){
        if(dateUtils == null){
            dateUtils = new DateUtils();
        }
        return dateUtils;
    }

    /**
     * 秒数换算“00:00”
     * @param second
     * @return
     */
    public String secondConvertIntoTime(int second){
        int hour = second / 3600;
        int minute = (second / 60) % 60;
        int secon = second % 60;
        String time;
        if (hour > 0) {
            time = BaseUtils.StaticParams.getNewText(hour) + ":"
                    + BaseUtils.StaticParams.getNewText(minute) + ":"
                    + BaseUtils.StaticParams.getNewText(secon);
        } else {
            time = BaseUtils.StaticParams.getNewText(minute) + ":"
                    + BaseUtils.StaticParams.getNewText(secon);
        }
        return time;
    }

    /**
     * 配速换算“00:00”  500m/min
     * @param speed
     * @return
     */
    public String speedAllocationConvertInto(int speed){
        String text;
        if (speed <= 0) {
            text = "00:00";
        } else {
            int time = (int) (1800 / (speed * 0.01) + 0.5);  //计算好了配速   //((info.time == 0 || info.distance < 10) ? 0 : (int) (500 / (info.distance * 1.0f / info.time) + 0.5f));//计算500需要多少秒
            int hour = time / 3600;
            int minute = (time / 60) % 60;
            int second = time % 60;
            if (hour > 0) {
                text = BaseUtils.StaticParams.getNewText(hour) + ":"
                        + BaseUtils.StaticParams.getNewText(minute) + ":"
                        + BaseUtils.StaticParams.getNewText(second);
            } else {
                text = BaseUtils.StaticParams.getNewText(minute) + ":"
                        + BaseUtils.StaticParams.getNewText(second);
            }
        }
        return text;
    }

    public String speedKmMin(int speed){
        String text;
        if (speed <= 0) {
            text = "00:00";
        }else {
            int time = (int) (60 / (speed * 0.01) + 1);  //计算好了配速   //((info.time == 0 || info.distance < 10) ? 0 : (int) (500 / (info.distance * 1.0f / info.time) + 0.5f));//计算500需要多少秒
            int hour = time / 3600;
            int minute = (time / 60) % 60;
            int second = time % 60;
            if (hour > 0) {
                text = BaseUtils.StaticParams.getNewText(hour) + ":"
                        + BaseUtils.StaticParams.getNewText(minute) + ":"
                        + BaseUtils.StaticParams.getNewText(second);
            } else {
                text = BaseUtils.StaticParams.getNewText(minute) + ":"
                        + BaseUtils.StaticParams.getNewText(second);
            }
        }
        return text;
    }

}
